#ifndef _BALANCE_HPP_20120612
#define _BALANCE_HPP_20120612

#include <ext/hash_map>

#include "singleton.hpp"
#include "cmd_parser.hpp"
#include "balance_cmd.hpp"
#include "confsvr_cmd.hpp"
#include "acceptor_manager.hpp"

#include "basesvr.hpp"

#include "node.hpp"

using namespace mina;
using namespace cmd;

typedef SSBalanceRes BalanceConf;

class Balance : public BaseSvr, public Singleton<Balance>
{
	public :
		friend class Singleton<Balance>;

	public :
		typedef AcceptorManager Reactor;

	public :
		virtual ~Balance() { finish(); }

		template <typename _Msg>
			int handle(Connection & conn, _Msg & msg)
			{
				assert(false);
				return 0;
			}

		int regist();

		// should implement those function
		virtual int impl_init();
		virtual int process();
		virtual int reload();
		virtual int finish();
		
		Reactor * reactor()               { return _reactor; }

	public :
		Reactor         *  _reactor;

		BalanceConf        _conf;

	public :
		const static int MAX_NODE = 128;

		int                _node_num;
		Node               _nodes[MAX_NODE];

		Processor<Balance> _processor;
		CmdParser          _parser;
};

#endif

